package com.wms.function.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wms.common.annotation.Log;
import com.wms.common.core.controller.BaseController;
import com.wms.common.core.domain.AjaxResult;
import com.wms.common.enums.BusinessType;
import com.wms.function.domain.TbInventoryHistory;
import com.wms.function.service.ITbInventoryHistoryService;
import com.wms.common.utils.poi.ExcelUtil;
import com.wms.common.core.page.TableDataInfo;

/**
 * 库存操作记录Controller
 *
 * @author ruoyi
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/function/history")
@Api(tags = "库存操作记录的接口")
public class TbInventoryHistoryController extends BaseController {
    @Autowired
    private ITbInventoryHistoryService tbInventoryHistoryService;

/**
 * 查询库存操作记录列表
 */
@ApiOperation("查询库存操作记录列表")
@PreAuthorize("@ss.hasPermi('function:history:list')")
@GetMapping("/list")
    public TableDataInfo list(TbInventoryHistory tbInventoryHistory) {
        startPage();
        List<TbInventoryHistory> list = tbInventoryHistoryService.selectTbInventoryHistoryList(tbInventoryHistory);
        return getDataTable(list);
    }

    /**
     * 导出库存操作记录列表
     */
    @ApiOperation("导出库存操作记录列表")
    @PreAuthorize("@ss.hasPermi('function:history:export')")
    @Log(title = "库存操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbInventoryHistory tbInventoryHistory) {
        List<TbInventoryHistory> list = tbInventoryHistoryService.selectTbInventoryHistoryList(tbInventoryHistory);
        ExcelUtil<TbInventoryHistory> util = new ExcelUtil<TbInventoryHistory>(TbInventoryHistory. class);
        util.exportExcel(response, list, "库存操作记录数据");
    }

    /**
     * 获取库存操作记录详细信息
     */
    @ApiOperation("获取库存操作记录详细信息")
    @PreAuthorize("@ss.hasPermi('function:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(value = "库存操作记录ID", required = true)
                              @PathVariable("id") Long id) {
        return success(tbInventoryHistoryService.selectTbInventoryHistoryById(id));
    }

    /**
     * 新增库存操作记录
     */
    @ApiOperation("新增库存操作记录")
    @PreAuthorize("@ss.hasPermi('function:history:add')")
    @Log(title = "库存操作记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(value = "库存操作记录实体")
                          @RequestBody TbInventoryHistory tbInventoryHistory) {
        return toAjax(tbInventoryHistoryService.insertTbInventoryHistory(tbInventoryHistory));
    }

    /**
     * 修改库存操作记录
     */
    @ApiOperation("修改库存操作记录")
    @PreAuthorize("@ss.hasPermi('function:history:edit')")
    @Log(title = "库存操作记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(value = "库存操作记录实体")
                           @RequestBody TbInventoryHistory tbInventoryHistory) {
        return toAjax(tbInventoryHistoryService.updateTbInventoryHistory(tbInventoryHistory));
    }

    /**
     * 删除库存操作记录
     */
    @ApiOperation("删除库存操作记录")
    @PreAuthorize("@ss.hasPermi('function:history:remove')")
    @Log(title = "库存操作记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbInventoryHistoryService.deleteTbInventoryHistoryByIds(ids));
    }
}
